<?php $this->beginBlock('main')?>
	<div id="page_wrapper">
		<div id="page-header">
			<div class="fixed" id="page-header-wrapper">
				<div id="top">
					<!-- http://demo.admintasia.com/dashboard.php -->
					<a href="/" target="_blank" class="logo" title="ecbond">ecbond</a>
					<div class="welcome">
						<span class="note"><?php echo $this->identity->getName()?></span>
<!--						<a class="btn ui-state-default ui-corner-all" href="#">-->
<!--							<span class="ui-icon ui-icon-wrench"></span>-->
<!--							Settings-->
<!--						</a>-->
						<a class="btn ui-state-default ui-corner-all" href="<?php echo $this->buildUrl('*/login/logout/index')?>">
							<span class="ui-icon ui-icon-power"></span>
							退出
						</a>						
					</div>
				</div>
				<ul class="sf-js-enabled" id="navigation">
<?php                    
function buildMenuTree($parentId, $menus, $lang){
    if($parentId == 0){
        $html = '';
        foreach($menus as $menu){
            if($menu['parent_id'] == $parentId){
                if($GLOBALS[RC]->getIdentity()->isInAnyRole($menu['role_codes'])){
                    $html .= '<li class="sfHover"><a href="javascript:void(0)" class="sf-with-ul">'
                          . $lang->__($menu['name'])
                          . '<span class="ui-icon-carat-1-s ui-icon"></span>'
                          . '</a>'
                          . buildMenuTree($menu['id'], $menus, $lang)
                          . '</li>';
                }
            }
        }
        return $html;
    }else{
        $html = '';
        foreach($menus as $menu){
            if($menu['parent_id'] == $parentId){
                if($GLOBALS[RC]->getIdentity()->isInAnyRole($menu['role_codes'])){
                    $html .= '<li>'
                          . '<a href="'.$GLOBALS[RC]->getRouter()->buildUrl('backend'.$menu['url']).'">'
                          . $lang->__($menu['name'])
                          . '</a>'
                          . buildMenuTree($menu['id'], $menus, $lang)
                          . '</li>';
                }
            }
        }
        if(!empty($html)){
            $html = '<ul style="display: block; visibility: visible;">' . $html . '</ul>';
        }
        return $html;
    }
}
$menus = App::getModel('system/menu')
            ->getQuery()
            ->orderby('parent_id', 'asc')
            ->orderby('sort', 'asc')
            ->fetchCollection()
            ->toArray();
echo buildMenuTree(0, $menus, $GLOBALS[RC]->getLanguage());
?>
				</ul>				
			</div>							
		</div>
		<?php echo $this->loadTemplate('block'.DS.'message')?>
		<div id="sub-nav">
			<div class="page-title">
				<span><?php echo $this->loadTemplate('block'.DS.'location')?></span>
			</div>
			<div id="top-buttons">
				<?php echo $this->renderBlock('toolbar') ?>
			</div>
		</div>		
		<?php echo $this->renderBlock()?>
	</div>
<?php $this->endBlock()?>
<?php echo $this->extend('template'.DS.'base')?>
